home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
526-550
/
disk_534
/
term
/
source.lzh
/
SpeechPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-20
|
12KB
|
414 lines
/* $Revision Header * Header built automatically - do not edit! *************
*
* (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
*
* Name .....: SpeechPanel.c
* Created ..: Thursday 27-Jun-91 20:01
* Revision .: 0
*
* Date Author Comment
* ========= ======== ====================
* 27-Jun-91 Olsen Created this file!
*
* $Revision Header ********************************************************/
#include "TermGlobal.h"
#define WIDTH 319
#define HEIGHT 118
enum { GAD_RATE,GAD_PITCH,GAD_FREQUENCY,GAD_VOLUME,
GAD_SEX,GAD_SPEECH,GAD_SPEAK,
GAD_USE,GAD_LOAD,GAD_SAVE,GAD_CANCEL };
enum { MEN_USE=1,MEN_LOAD,MEN_SAVESPEECH,MEN_CANCEL };
STATIC struct NewMenu SpeechMenu[] =
{
{ NM_TITLE, "Project", 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Load", "L", 0, 0, (APTR)MEN_LOAD},
{ NM_ITEM, "Save", "S", 0, 0, (APTR)MEN_SAVESPEECH},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Use", "U", 0, 0, (APTR)MEN_USE},
{ NM_ITEM, "Cancel", "C", 0, 0, (APTR)MEN_CANCEL},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Quit", "Q", 0, 0, (APTR)MEN_CANCEL},
{ NM_END, 0, 0 , 0, 0, (APTR)0}
};
STATIC UBYTE *Sex[3] =
{
"Male",
"Female",
NULL
};
STATIC struct Gadget *
CreateAllGadgets(struct SpeechConfig *SpeechConfig,struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
LONG Counter = 0;
if(Gadget = CreateContext(GadgetList))
{
NewGadget . ng_Width = 100;
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = "Rate (Words/Minute) ";
NewGadget . ng_TextAttr = &DefaultFont;
NewGadget . ng_VisualInfo = VisualInfo;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = NG_HIGHLABEL;
NewGadget . ng_LeftEdge = (strlen(NewGadget . ng_GadgetText) + 2) * 8 + 1;
NewGadget . ng_TopEdge = 1 + TopEdge;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GTSL_Min, MINRATE,
GTSL_Max, MAXRATE,
GTSL_Level, SpeechConfig -> Rate,
GTSL_LevelFormat, "%3ld",
GTSL_MaxLevelLen, 3,
TAG_DONE);
NewGadget . ng_GadgetText = "Pitch (Hz) ";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 3;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GTSL_Min, MINPITCH,
GTSL_Max, MAXPITCH,
GTSL_Level, SpeechConfig -> Pitch,
GTSL_LevelFormat, "%3ld",
GTSL_MaxLevelLen, 3,
TAG_DONE);
NewGadget . ng_GadgetText = "Frequency (Hz) ";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 3;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GTSL_Min, MINFREQ,
GTSL_Max, MAXFREQ,
GTSL_Level, SpeechConfig -> Frequency,
GTSL_LevelFormat, "%5ld",
GTSL_MaxLevelLen, 5,
TAG_DONE);
NewGadget . ng_GadgetText = "Volume ";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 3;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GTSL_Min, MINVOL,
GTSL_Max, MAXVOL,
GTSL_Level, SpeechConfig -> Volume,
GTSL_LevelFormat, "%2ld",
GTSL_MaxLevelLen, 2,
TAG_DONE);
NewGadget . ng_GadgetText = "Sex";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 3;
GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
GTCY_Labels, Sex,
GTCY_Active, SpeechConfig -> Sex,
TAG_DONE);
NewGadget . ng_GadgetText = "Speech enabled";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GTCB_Checked, SpeechConfig -> Enabled,
TAG_DONE);
NewGadget . ng_GadgetText = "Speak!";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = 10;
NewGadget . ng_Width = WIDTH - 20;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
TAG_DONE);
NewGadget . ng_Width = 52;
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = "_Use";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
NewGadget . ng_LeftEdge = 10;
NewGadget . ng_TopEdge = HEIGHT - 3 - NewGadget . ng_Height;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = "_Load";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + WIDTH / 4 + 4;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = "_Save";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + WIDTH / 4 + 4;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = "_Cancel";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = WIDTH - 10 - NewGadget . ng_Width;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
}
return(Gadget);
}
VOID
SpeechPanel()
{
struct Window *PanelWindow;
struct Menu *PanelMenu;
struct Gadget *GadgetList;
struct Gadget *GadgetArray[GAD_CANCEL + 1];
struct SpeechConfig PrivateConfig;
UBYTE DummyBuffer[256],*DummyChar;
struct FileRequest *FileRequest;
CopyMem(&SpeechConfig,&PrivateConfig,sizeof(struct SpeechConfig));
if(CreateAllGadgets(&SpeechConfig,&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
{
if(PanelMenu = CreateMenus(SpeechMenu,
GTMN_FrontPen, 0,
TAG_DONE))
{
if(LayoutMenus(PanelMenu,VisualInfo,
GTMN_TextAttr,&DefaultFont,
TAG_DONE))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, (Screen -> Width - WIDTH) >> 1,
WA_Top, (Screen -> Height - HEIGHT) >> 1,
WA_Width, WIDTH,
WA_Height, HEIGHT,
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Screen,
WA_IDCMP, IDCMP_CLOSEWINDOW | SLIDERIDCMP | CHECKBOXIDCMP | IDCMP_MENUPICK,
WA_Title, "Speech Preferences",
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG Class,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
PushWindow(PanelWindow);
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
SetMenuStrip(PanelWindow,PanelMenu);
PanelWindow -> Flags &= ~WFLG_RMBTRAP;
while(!Terminated)
{
WaitPort(PanelWindow -> UserPort);
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
Class = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
if(Class == IDCMP_MENUPICK)
{
struct MenuItem *MenuItem;
while(Code != MENUNULL)
{
MenuItem = ItemAddress(PanelMenu,Code);
switch((ULONG)MENU_USERDATA(MenuItem))
{
case MEN_CANCEL: Class = IDCMP_CLOSEWINDOW;
break;
case MEN_USE: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_USE];
break;
case MEN_LOAD: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_LOAD];
break;
case MEN_SAVESPEECH: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_SAVE];
break;
default: break;
}
Code = MenuItem -> NextSelect;
}
}
if(Class == IDCMP_CLOSEWINDOW)
Terminated = TRUE;
if(Class == IDCMP_MOUSEMOVE)
{
switch(Gadget -> GadgetID)
{
case GAD_RATE: SpeechConfig . Rate = Code;
break;
case GAD_PITCH: SpeechConfig . Pitch = Code;
break;
case GAD_FREQUENCY: SpeechConfig . Frequency = Code;
break;
case GAD_VOLUME: SpeechConfig . Volume = Code;
break;
}
}
if(Class == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_USE: Terminated = TRUE;
break;
case GAD_CANCEL: Terminated = TRUE;
CopyMem(&PrivateConfig,&SpeechConfig,sizeof(struct SpeechConfig));
SpeechSetup();
break;
case GAD_SEX: SpeechConfig . Sex = Code;
break;
case GAD_SPEECH: SpeechConfig . Enabled = (Gadget -> Flags & GFLG_SELECTED ? TRUE : FALSE);
break;
case GAD_LOAD: strcpy(DummyBuffer,LastSpeech);
DummyChar = PathPart(DummyBuffer);
*DummyChar = 0;
SetWait(PanelWindow);
PanelWindow -> Flags |= WFLG_RMBTRAP;
if(FileRequest = GetFile("Load Speech Settings...",DummyBuffer,FilePart(LastSpeech),DummyBuffer,"#?.term",FALSE,FALSE))
{
if(!ReadIFFData(DummyBuffer,&SpeechConfig,sizeof(struct SpeechConfig),'SPEK'))
MyEasyRequest(Window,"Couldn't load speech settings\n\"%s\"!","Continue",DummyBuffer);
else
{
strcpy(LastSpeech,DummyBuffer);
GT_SetGadgetAttrs(GadgetArray[GAD_RATE],PanelWindow,NULL,
GTSL_Level,SpeechConfig . Rate,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_PITCH],PanelWindow,NULL,
GTSL_Level,SpeechConfig . Pitch,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_FREQUENCY],PanelWindow,NULL,
GTSL_Level,SpeechConfig . Frequency,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_VOLUME],PanelWindow,NULL,
GTSL_Level,SpeechConfig . Volume,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_SEX],PanelWindow,NULL,
GTCY_Active,SpeechConfig . Sex,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_SPEECH],PanelWindow,NULL,
GTCB_Checked,SpeechConfig . Enabled,
TAG_DONE);
SpeechSetup();
}
}
ClearPointer(PanelWindow);
PanelWindow -> Flags &= ~WFLG_RMBTRAP;
break;
case GAD_SAVE: strcpy(DummyBuffer,LastSpeech);
DummyChar = PathPart(DummyBuffer);
*DummyChar = 0;
SetWait(PanelWindow);
PanelWindow -> Flags |= WFLG_RMBTRAP;
if(FileRequest = GetFile("Save Speech Settings...",DummyBuffer,FilePart(LastSpeech),DummyBuffer,"#?.term",TRUE,FALSE))
{
if(!WriteIFFData(DummyBuffer,&SpeechConfig,sizeof(struct SpeechConfig),'SPEK'))
MyEasyRequest(Window,"Couldn't save speech settings\n\"%s\"!","Continue",DummyBuffer);
else
strcpy(LastSpeech,DummyBuffer);
}
ClearPointer(PanelWindow);
PanelWindow -> Flags &= ~WFLG_RMBTRAP;
break;
case GAD_SPEAK: SpeechSetup();
Say("This is term speaking.");
break;
}
}
}
}
PanelWindow -> Flags |= WFLG_RMBTRAP;
ClearMenuStrip(PanelWindow);
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
}
FreeMenus(PanelMenu);
}
FreeGadgets(GadgetList);
}
}